<template>
  <div :style="styleItem">
		<!-- :style="{height: styleItem.height, width: styleItem.width}" -->
    <div id="ShelvesCharts"></div>
  </div>
</template>

<script>
// 19 上架   20下架
import * as echarts from "echarts";
export default {
  name: "ShelvesCharts",
	props: {
		styleItem:  {
      type: Object,
      default: () => {}
    },
		Totalarchives: {
      type: Array,
      default: () => []
    },
		xData: {
      type: Array,
      default: () => []
    },
		data1: {
      type: Array,
      default: () => []
    },
    shelvesData: {
      type: Array,
      default: () => []
    }
	},
  data() {
    return {
			myChart: null,
      onShelfData: [],
      onShelfTime: [],
      offShelfData: [],
      offShelfTime: [],

		};
  },
  mounted() {
    this.showChart();
  },
  methods: {
		reloadChart() {
			// console.log('重庆哦', this.styleItem)
			this.myChart.clear()
      this.getMoreData()
			this.showChart();
		},
    getMoreData() {
      this.onShelfData = []
      this.onShelfTime = []
      this.offShelfData = []
      this.offShelfTime = []

      this.shelvesData.map(m => {
        if (m.action == 19) {
          this.onShelfData.push(m.total)
          this.onShelfTime.push(m.day)
        }
        if (m.action == 20) {
          this.offShelfData.push(m.total)
          this.offShelfTime.push(m.day)
        }
      })
    },
    showChart() {
			if (this.myChart != null && this.myChart != "" && this.myChart != "undefined") {
        this.myChart.dispose();
      }
      var chartDom = document.getElementById("ShelvesCharts");
      this.myChart = echarts.init(chartDom);
      var option;

			// console.log(this.Totalarchives, 'Totalarchives')

      option = {
				// x轴
				xAxis: [
          {
            type: "category",
            data: this.onShelfTime,

            triggerEvent: true,
            axisTick: {
              show: false,
              inside: true,
              lineStyle: {
                color: "#ccc"
              }
            },
            axisLine: {
              show: true,
              lineStyle: {
                color: "rgba(69, 240, 234, 1)"
              }
            },
            axisLabel: {
              color: "#ccc",
              fontSize: this.$fontSize.fontSize(0.12),
              // fontWeight: 300
            }
          }
        ],
				yAxis: [
          {
            type: "value",
						// data: this.Totalarchives,
						splitLine: {
              show: true,
              lineStyle: {
                type: "solid",
                width: 1,
                color: "#636363"
              }
            },
						axisLine: {
              show: true,
              lineStyle: {
                color: "rgba(69, 240, 234, 1)"
              }
            },
						axisLabel: {
              color: "#ccc",
              fontSize: this.$fontSize.fontSize(0.12)
            }
					}
				],
       
				color: ["rgb(1, 217, 254)"],
				tooltip: {
          trigger: "axis",
          axisPointer: {
            // 坐标轴指示器，坐标轴触发有效
            type: "shadow", // 默认为直线，可选为：'line' | 'shadow'
            shadowStyle: {
              // 阴影指示器样式设置
              width: "auto", // 阴影大小
              color: "rgba(150,150,150,0.3)" // 阴影颜色
            }
          }
        },
				legend: {
          // icon: "rect",
          top: "0",
          right: "2%",
          // // bottom: 0,
          itemWidth: this.$fontSize.fontSize(0.1),
          itemHeight: this.$fontSize.fontSize(0.1),
          itemGap: this.$fontSize.fontSize(0.12),
          textStyle: {
            color: "#fff",
            fontSize: this.$fontSize.fontSize(0.1),
          },
          data: ["上架量", "下架量"]
        },
				grid: {
          top: "22%", // 组件离容器上侧的距离,百分比字符串或整型数字
          left: "5%", // 组件离容器左侧的距离,百分比字符串或整型数字
          right: "5%",
          bottom: "3%",
          containLabel: true //grid 区域是否包含坐标轴的刻度标签，
        },
        // series: [
        //   {
        //     data: this.Totalarchives,
				// 		// [120, 200, 150, 80, 70, 110, 130],
        //     type: "bar",
        //   },
        // ],
				series: [
          {
            name: "上架量",
            type: "bar",
            barWidth: this.$fontSize.fontSize(0.2),
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#01d8fe"
                  },

                  {
                    offset: 1,
                    color: "#047bd7"
                  }
                ]),
                label: {
                  show: true, //开启显示
                  position: "top", //在上方显示
                  offset: [-4, 3], //偏移量
                  textStyle: {
                    //数值样式
                    color: "#fff",
                    fontSize: this.$fontSize.fontSize(0.1)
                  }
                }
              }
            },
            data: this.onShelfData
          },
					{
            name: "下架量",
            type: "bar",
            barWidth: this.$fontSize.fontSize(0.2),
            itemStyle: {
              normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                  {
                    offset: 0,
                    color: "#3fa062"
                  },

                  {
                    offset: 1,
                    color: "#057928"
                  }
                ]),
                label: {
                  show: true, //开启显示
                  position: "top", //在上方显示
                  offset: [4, 3], //偏移量
                  textStyle: {
                    //数值样式
                    color: "#fff",
                    fontSize: this.$fontSize.fontSize(0.1)
                  }
                }
              }
            },
            data: this.offShelfData
          }
        ]
      };

      option && this.myChart.setOption(option);

			window.addEventListener("resize", function() {
				// console.log('动了')
        // this.myChart.resize();
      });
    },
  },
};
</script>

<style lang="scss">
#ShelvesCharts {
	width: 100%;
	height: 100%;
}

</style>
